﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using MbUnit.Framework;
//using lucere.entity;
//using lucere.toolkit.extension;

//namespace lucere.test.entity
//{
//    [TestFixture]
//    public class TestBinaryDocument
//    {
//        const string _binaryValStored = "this text will be stored as a byte array in the index";
//        const string _binaryValCompressed = 
//            "this text will be also stored and compressed as a byte array in the index";

//        [Test]
//        public void TextBinaryFieldInIndex()
//        {
//            IFieldable binaryFldStored = new Field("binaryStored", _binaryValStored.GetBytes(), Store.Yes);
//            IFieldable stringFldStored = new Field("stringStored", _binaryValStored, Store.Yes, Index.No, TermVector.No);

//            try
//            {
//                //binary fields with store off are not allowed
//                IFieldable fieldTest = new Field("fail", _binaryValStored.GetBytes(), Store.No);
//                Assert.Fail();
//            }
//            catch (ArgumentException)
//            {
//            }

//            IDocument doc = new Document();

//            doc.Add(binaryFldStored);

//            doc.Add(stringFldStored);

//            //Test for field count
//            Assert.AreEqual<int>(2, doc.Fields.Count);

//            //Add the doc to a ram index
//            MockRAMDirectory dir = new MockRAMDirectory();
//            IIndexWriter writer = new IndexWriter(dir, 
//                new StandardAnalyzer(lucere.util.Version.LUCENE_CURRENT), 
//                true, IndexWriter.MaxFieldLength.LIMITED);
//            writer.AddDocument(doc);
//            writer.Close();

//            //open a reader and fetch the document
//            IIndexReader reader = IndexReader.Open(dir, false);
//            IDocument docFromReader = reader.Document(0);
//            Assert.IsTrue(docFromReader != null);

//            //fetch the binary stored field and compare it's content with the original one
//            //string binaryFldStoredTest = new string(docFromReader.GetBinaryValue("binaryStored").Cast<char>().ToArray());
//            string binaryFldStoredTest = BitConverter.ToString(docFromReader.GetBinaryValue("binaryStored"));
//            Assert.IsTrue(binaryFldStoredTest.Equals(_binaryValStored));

//            //delete the document from the index
//            reader.DeleteDocument(0);
//            Assert.AreEqual<int>(0, reader.NumDocs);

//            reader.Close();
//            dir.Close();
//        }

//        [Test]
//        public void TestCompressionTools()
//        {
//            IFieldable binaryFldCompressed = new Field("binaryCompressed",
//                    CompressionTools.Compress(_binaryValCompressed.GetBytes()), 
//                    Store.Yes);
//            IFieldable stringFldCompressed = new Field("stringCompressed",
//                CompressionTools.Compress(_binaryValCompressed), Store.Yes);

//            IDocument doc = new Document();

//            doc.Add(binaryFldCompressed);
//            doc.Add(stringFldCompressed);

//            //add the doc to a RAM index
//            MockRAMDirectory dir = new MockRAMDirectory();
//            IIndexWriter writer = new IndexWriter(dir, 
//                new StandardAnalyzer(lucene.util.Version.LUCENE_CURRENT),
//                true, IndexWriter.MaxFieldLength.LIMITED);
//            writer.AddDocument(doc);
//            writer.Close();

//            //open a reader and fetch the document
//            IIndexReader reader = IndexReader.Open(dir, false);
//            IDocument docFromReader = reader.Document(0);
//            Assert.IsTrue(docFromReader != null);

//            //Fetch the binary stored field and compare its content with the original one
//            string binaryFldCompressedTest = 
//                BitConverter.ToString(CompressionTools.Decompress(docFromReader.GetBinaryValue("binaryCompressed")));
//            Assert.IsTrue(binaryFldCompressedTest.Equals(_binaryValCompressed));
//            Assert.IsTrue(CompressionTools.DecompressString(BitConverter.ToString(
//                docFromReader.GetBinaryValue("stringCompressed"))).Equals(_binaryValCompressed));

//            reader.Close();
//            dir.Close();
//        }
//    }
//}
